﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SettingConfiguration_Serialize.cs" company="DevDigital">
//   DevDigital
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Settings.NET
{
    using System;

    /// <summary>
    /// Setting configuration
    /// </summary>
    public partial class SettingConfiguration    
    {
        /// <summary>
        /// The current serializer
        /// </summary>
        private ISettingsSerializer currentSerializer;

        /// <summary>
        /// Sets the current serializer.
        /// </summary>
        /// <typeparam name="TSerializer">The type of the serializer.</typeparam>
        /// <returns>The setting configuration</returns>
        public ISettingConfiguration WithSerializer<TSerializer>() where TSerializer : ISettingsSerializer, new()
        {
            var serializer = this.settingsProviderFactory.GetSerializer<TSerializer>();
            return this.WithSerializer(serializer);
        }

        /// <summary>
        /// Sets the current serializer.
        /// </summary>
        /// <param name="settingsSerializer">The settings serializer.</param>
        /// <returns>The setting configuration</returns>
        public ISettingConfiguration WithSerializer(ISettingsSerializer settingsSerializer)
        {
            if (settingsSerializer == null)
            {
                throw new ArgumentNullException("settingsSerializer", "No settings serializer specified");
            }

            this.currentSerializer = settingsSerializer;
            return this;
        }
    }
}